package com.ocm.burnningstar;

import android.app.Application;
import android.content.SharedPreferences;
import android.graphics.Typeface;

import com.blankj.utilcode.util.Utils;
import com.shape.sdk.ShapeCenter;
import com.tencent.bugly.Bugly;

import org.xutils.x;

/**
 * Created by ocm on 2018-01-16.
 */

public class GlobalApplication extends Application {
    private ShapeCenter shapeCenter;

    private static GlobalApplication instance;
    public static int storeId = 1;
    public static int stationId = 1;
    public static int stationCount = 6;
    public static Typeface typeFaceClass;
    public static Typeface typeFaceTxt;
    public static Typeface typeFaceNum;
    public static Typeface typeFaceNum_S;
    public static Typeface typeFaceNum_Ob;
     static GlobalApplication getInstance() {
        return instance;
    }
    @Override
    public void onCreate() {
        super.onCreate();
        Bugly.init(getApplicationContext(), "b1a2c567c9", false);
        x.Ext.init(this);
        x.Ext.setDebug(false); //输出debug日志，开启会影响性能
        Utils.init(this);
        instance = this;
        getDefaultParams();
        typeFaceClass = Typeface.createFromAsset(this.getAssets(),"fonts/createfont.ttf");
        typeFaceTxt = Typeface.createFromAsset(this.getAssets(),"fonts/PingFang Regular.ttf");
        typeFaceNum = Typeface.createFromAsset(this.getAssets(),"fonts/AvenirLTStd-Heavy.ttf");
        typeFaceNum_Ob = Typeface.createFromAsset(this.getAssets(),"fonts/AvenirLTStd-HeavyOblique.ttf");
        typeFaceNum_S = Typeface.createFromAsset(this.getAssets(),"fonts/AvenirLTStd-Medium.ttf");
//        CrashHandler crashHandler = CrashHandler.getInstance();
//        crashHandler.init(this,MainActivity.class);
    }


    public boolean saveDefaultParams(int _storeId,int _stationId,int _stationCount){
        SharedPreferences sharedPreferences = getSharedPreferences(getResources().getString(R.string.app_name),0);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("storeId",String.valueOf(_storeId));
        editor.putString("stationId",String.valueOf(_stationId));
        editor.putString("stationCount",String.valueOf(_stationCount));
        storeId = _storeId;
        stationId = _stationId;
        stationCount = _stationCount;
        return editor.commit();
    }

    public void getDefaultParams(){
        SharedPreferences sharedPreferences = getSharedPreferences(getResources().getString(R.string.app_name),0);
        storeId = sharedPreferences.getInt("storeId",1);
        stationId = sharedPreferences.getInt("stationId",1);
        stationCount = sharedPreferences.getInt("stationCount",6);
    }
    public ShapeCenter getShapeCenter() {
        return shapeCenter;
    }
}
